<%@include file="/WEB-INF/templates/configuration.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@page import="nl.hva.web.mvcwebapp.models.UploadedAssignments"%>
<%
HttpSession session_user = request.getSession(true);
    String firstname = (String) session_user.getAttribute("user_firstname");
    int user_id = 0;
    int user_type=0;
    if(firstname!=null){
        user_id = Integer.valueOf("" + session_user.getAttribute("user_id"));
        user_type = Integer.valueOf("" + session_user.getAttribute("user_type"));
    }

%>
<h2><b>Uploaded Assignments: </b>${chapter.chapterName} </h2>
<c:choose>
    <c:when test="${amounttests != 0}">
        <!-- Wanneer er gebruikers opgeslagen zijn, worden ze hier getoond -->
        <table class="zebra">
            <tr>
                <td style="width:100px"> 
                    <strong>User</strong>
                </td>
                <td style="width:100px"> 
                    <strong>Assignment Name</strong>
                </td>
                <td style="width:200px">
                    <strong>Assignment Description</strong>
                </td>
                <td style="width:100px">
                    <strong>Uploaded?</strong>
                </td>
                <td style="width:100px">
                    <strong>Done?</strong>
                </td>
                <td></td>
            </tr>
            <c:forEach var="tempAssignment" items="${assignments}">
                <!-- Per gebruiker wordt nu een rij aangemaakt met daarin zijn gegevens -->
                <% 
                                   UploadedAssignments document = (UploadedAssignments) pageContext.getAttribute("tempAssignment");
                                   int approved = document.getApproved(); 
                                   int uploaded = 1;
                %>
                <%--<c:choose>
                      <c:when test="${documents.size() != 0}">
                          <c:forEach var="tempDocument" items="${documents}">
                              <c:choose>
                                  <c:when test="${tempDocument.uploadassignment.uploadassignmentid == tempAssignment.uploadassignmentid}">
                                      
                                      <% 
                                      document = (UploadedAssignments) pageContext.getAttribute("tempDocument");
                                      approved = document.getApproved(); 
                                      //score = usertest.getScore();
                                      uploaded = 1;
                                      %>
                                  </c:when>
                                  <c:otherwise>
                                  </c:otherwise>
                              </c:choose>
                          </c:forEach>
                      </c:when>
                </c:choose>--%>
                <tr class="<%=(approved == 1)?"test-completed":""%>">
                    <td>
                        ${tempAssignment.user.userName}
                    </td>
                    <td>
                        ${tempAssignment.uploadassignment.uploadassignmentname}
                    </td>
                    <td style="width:200px">
                        <div class="description">${tempAssignment.uploadassignment.uploadassignmentdescription}</div>
                    </td>
                    <td  style="width:100px">
                        <div style="height:30px; width:30px" class="<%=(uploaded == 1)?"check-icon":""%>"><%=(uploaded == 1)?"":"-"%></div>
                    </td>
                    <td  style="width:100px">
                        <div style="height:30px; width:30px" class="<%=(approved == 1)?"check-icon":""%>"><%=(approved == 1)?"":"-"%></div>
                    </td>
                    <td style="width:100px">

                        <%
                        if(approved==0){
                            if(uploaded==1){
                        %>
                        <a class="icon view" href="${url}chapter/uploadedassignment/view?documentid=${tempAssignment.uploadedassignmentid}">view</a> 
                        <%
                    }else{
                        %>
                        <a class="icon view" href="${url}chapter/uploadedassignment/new?uploadassignmentid=${tempAssignment.uploadassignment.uploadassignmentid}">view</a> 
                        <%      
                    }
                        %>
                        <%if (user_type == 2 || user_type == 3) {%>
                        <a class="icon edit" href="${url}chapter/uploadassignment/edit?uploadassignmentid=${tempAssignment.uploadassignment.uploadassignmentid}">edit</a> 
                        <a class="icon delete" href="${url}chapter/test/delete?testid=${tempAssignment.uploadassignment.uploadassignmentid}">delete</a>
                        <%}%>
                        <%}%>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </c:when>
    <c:otherwise>
        <!-- Als er geen cursussen zijn, wordt deze melding getoond -->
        There are no tests found.
    </c:otherwise>
</c:choose>

<p>
    <a class="button" href="${url}index">Back to index</a>
    <a class="button" href="${url}chapter/view?chapterid=${chapter.chapterid}">Back to Chapter</a>
</p>